using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;

using Toenda.Foundation.Data;
using Toenda.Foundation.BackupRestoreHandler;

namespace CTestApplication {
	class Program {
		private static bool _not_finish = true;

		/// <summary>
		/// Default Main
		/// </summary>
		/// <param name="args"></param>
		static void Main(string[] args) {
			while(_not_finish) {
				ConsoleHeader();

				string filename = "MovieMaticTest_20090227193305.bak";

				Console.WriteLine("filename: " + filename);

				BackupRestoreHandler bu = new BackupRestoreHandler("");

				DateTime datetime = bu.GetDateTimeFromBackupFilename(filename);

				Console.WriteLine("filename: " + datetime.ToString());
				
				//ConsoleFooter();

				_not_finish = RepeatQuestion();
			}
		}

		/// <summary>
		/// Display a header
		/// </summary>
		public static void ConsoleHeader() {
			Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
			Console.WindowHeight = 45;
			Console.WindowWidth = 110;
			Console.Title = "TFL Console Test Application";
			Console.ForegroundColor = ConsoleColor.White;
			Console.BackgroundColor = ConsoleColor.DarkBlue;
			Console.Clear();

			Console.WriteLine("");
			Console.WriteLine("Toenda Foundation Library");
			Console.WriteLine("Console Test Application");
			Console.WriteLine("Version " + AssemblyInfo.Version);
			Console.WriteLine("Press [STRG+C] to exit.");
			Console.WriteLine("------------------------------------------------------------------");
			Console.WriteLine("");
		}

		/// <summary>
		/// Display a footer
		/// </summary>
		public static void ConsoleFooter() {
			Console.WriteLine("");
			Console.WriteLine("------------------------------------------------------------------");
			Console.WriteLine("Press [Return] to exit...");
			Console.ReadLine();
		}

		/// <summary>
		/// Display a repeat question
		/// </summary>
		public static bool RepeatQuestion() {
			Console.WriteLine("");
			Console.WriteLine("");
			Console.WriteLine("------------------------------------------------------------------");
			Console.WriteLine("Press [y] to repeat or any other key to exit...");
			Console.Write("Command: ");

			string cmd = "";

			try {
				cmd = Console.ReadLine().Trim();
			}
			catch(Exception) {
			}

			bool ret = (cmd.Length > 0
				? (cmd.Substring(0, 1) == "y" ? true : false)
				: false);

			Console.Clear();

			return ret;
		}

		/// <summary>
		/// Event Console_CancelKeyPress
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
			Console.WriteLine("");
			Console.WriteLine(" -------------------------------------------");
			Console.WriteLine("     EXIT MESSAGE");
			Console.WriteLine(" -------------------------------------------");
			Console.WriteLine("");
			System.Threading.Thread.Sleep(750);
		}
	}
}
